package com.yrline.pay.config;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yrline.pay.web.ResponseVo;

@RestControllerAdvice
public class ExceptionHanler {
	private Logger log = LoggerFactory.getLogger(ExceptionHanler.class);
	@Autowired
	private ObjectMapper om;

	@ExceptionHandler(value=Throwable.class)
	public Object  handleSQLException(HttpServletRequest request,
			Exception ex) {
		log.error("",ex);
		String header = request.getHeader("X-Requested-With");
		
		if (header != null && header.trim().equalsIgnoreCase("XMLHttpRequest")) {
			return new ResponseVo(false, 500, "访问出错");

		} else {
			ModelAndView	model = new ModelAndView("error");
			model.addObject("e", ex);
			model.addObject("uri", request.getRequestURI());
			return model;
		}
		

	}

}
